<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>药品列表页</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!-- 引入EasyUI的相关css和js文件 -->
<link href="EasyUI/themes/default/easyui.css" rel="stylesheet"
	type="text/css" />
<link href="EasyUI/themes/icon.css" rel="stylesheet" type="text/css" />
<link href="EasyUI/demo.css" rel="stylesheet" type="text/css" />
<script src="EasyUI/jquery.min.js" type="text/javascript"></script>
<script src="EasyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="EasyUI/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body>
	<table id="dg_druginfo" class="easyui-datagrid"></table>
	<!-- 创建datagrid控件的工具栏 -->
	<div id="tb_druginfo" style="padding: 2px 5px;">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="addDrug();">添加</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="updateDrug();">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" onclick="deleteDrug();" plain="true">删除</a>
	</div>
	<!-- 创建查询工具栏 -->
	<div id="searchtb_druginfo" style="padding: 2px 5px;">
		<form id="searchForm_druginfo" method="post">
			<div style="padding: 3px">
				药品编号&nbsp;&nbsp;<input class="easyui-textbox" name="id"
					id="search_drugno" style="width: 110px" />
			</div>
			<div style="padding: 3px">
				药品名称&nbsp;&nbsp;<input class="easyui-textbox" name="name"
					id="search_drugname" style="width: 110px" /> &nbsp;&nbsp;<a
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-search" plain="true" onclick="searchDrug();">查找</a>
			</div>
		</form>
	</div>

	<!-- 添加药品信息对话框(缺少药品备注，基本单位，用量限制) -->
	<div id="dlg_druginfo" class="easyui-dialog" title="添加药品" closed="true"
		style="width: 500px;">
		<div style="padding: 10px 60px 20px 60px">
			<form id="ff_druginfo" method="POST" action="">
				<table cellpadding="5">

					<tr>
						<td>药品名称:</td>
						<td><input class="easyui-textbox" type="text" id="drugname"
							name="drugname" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>药品编码:</td>
						<td><input class="easyui-textbox" type="text" id="drugno"
							name="drugno" data-options="required:true"></input></td>
					</tr>

					<tr>
						<td>商品规格:</td>
						<td><input class="easyui-textbox" type="text"
							id="drugspecification" name="drugspecification"
							data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>药品类型:</td>
						<td><select class="easyui-combobox" name="drugtype"
							id="drugtype"><option value="西药">西药</option>
								<option value="中药">中药</option></select></td>
					</tr>
					<tr>
						<td>商品价格:</td>
						<td><input class="easyui-textbox" type="text" id="drugprice"
							name="drugprice" data-options="required:true"></input></td>
					</tr>

					<tr>
						<td>药品单位:</td>
						<td><input class="easyui-textbox" type="text" id="sunit"
							name="sunit" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>药品备注:</td>
						<td><input class="easyui-textbox" name="drugremark"
							id="drugremark" data-options="multiline:true"
							style="height: 60px"></input></td>
					</tr>

				</table>
			</form>
			<div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="saveDrug();">保存</a> <a href="javascript:void(0)"
					class="easyui-linkbutton" onclick="clearForm();">清空</a>
			</div>
		</div>
	</div>
	<!-- 删除药品信息对话框 -->
	<div id="dlg_deletedruginfo" class="easyui-dialog" title="删除药品"
		closed="true" style="width: 500px;">
		<div style="padding: 10px 60px 20px 60px">
			<div style="text-align: center; padding: 5px">
				确定要删除药品？<br>
				<form id="ff_deletedruginfo" method="POST" action="">
					<tr>
						<td>药品编码:</td>
						<td><input class="easyui-textbox" type="text" id="drugno"
							name="drugno" data-options="required:true" readonly="readonly"
							style="width: 100%;"></input></td>
					</tr>
				</form>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="deleteDrugDlg();">删除</a>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		$(function() {
			$('#dg_druginfo').datagrid({
				singleSelect : true, //设置datagrid为单选
				url : 'drug/querybyform', //为datagrid设置数据源
				//pagination : true, //启用分页
				//pageSize : 10, //设置初始每页记录数（页大小）
				//pageList : [ 10, 15, 20 ], //设置可供选择的页大小
				rownumbers : true, //显示行号
				fit : true, //设置自适应
				toolbar : '#tb_druginfo', //为datagrid添加工具栏
				
				header : '#searchtb_druginfo', //为datagrid标头添加搜索栏
				columns : [ [ { //编辑datagrid的列
					title : '序号',
					field : 'no',
					align : 'center',
					checkbox : true
				}, {
					field : 'drugno',
					title : '药品编码',
					width : 150
				}, {
					field : 'drugname',
					title : '药品名称',
					align : 'center',
					width : 150
				}, {
					field : 'drugtype',
					title : '药品类型',

					width : 60
				}, /*{
								field : 'status',
								title : '药品状态',					
								width : 60
							},*/{
					field : 'sunit',
					title : '基本单位',
					width : 100
				}, {
					field : 'drugspecification',
					title : '规格',
					width : 120
				}, {
					field : 'drugprice',
					title : '价格',
					width : 50
				},/* {
									field : 'num',
									title : '库存',
									width : 50
								}, */{
					field : 'drugremark',
					title : '药品备注',
					width : 450
				} ] ]
			});
		});
		//查询药品
		function searchDrug() {
			var search_drugname = $('#search_drugname').textbox("getValue");
			var search_drugno = $('#search_drugno').textbox("getValue");

			$("#dg_druginfo").datagrid('load', {
				"drugno" : search_drugno,
				"drugname" : search_drugname
			});
		}
		// 打开新增药品对话框
		function addDrug() {
			$('#dlg_druginfo').dialog('open').dialog('setTitle', '新增药品');
			$("#drugno").textbox('textbox').attr('readonly',false);
			$("#drugname").textbox('textbox').attr('readonly',false);
			$('#ff_druginfo').form('clear');
			urls = 'drug/adddrug';
		}
		//保存信息
		function saveDrug() {
			$("#ff_druginfo").form("submit", {
				url : urls, //使用参数				
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.success == 'true') {
						$("#dg_druginfo").datagrid("reload");
						$("#dlg_druginfo").dialog("close");
					}
					$.messager.show({
						title : "提示信息",
						msg : result.message
					});
				}
			});
		}
		//清空信息
		function clearForm() {
			$('#ff_druginfo').form('clear');
		}
		//修改商品（对话框和新增公用）

		function updateDrug() {
			var rows = $("#dg_druginfo").datagrid('getSelections');
			if (rows.length > 0) {
				$("#drugno").textbox('textbox').attr('readonly',true);
				$("#drugname").textbox('textbox').attr('readonly',true);
				var row = $("#dg_druginfo").datagrid("getSelected");
				if (row) {
					$("#dlg_druginfo").dialog("open").dialog('setTitle',
							'修改药品信息');

					$("#ff_druginfo").form("load", {
						"drugname" : row.drugname,
						"drugno" : row.drugno,
						"drugspecification" : row.drugspecification,
						"drugprice" : row.drugprice,
						"sunit" : row.sunit,
						"drugtype" : row.drugtype,

					});
					
					urls = "drug/updatedrug";
				}
			} else {
				$.messager.alert('提示', '请选择要修改的行', 'info');
			}
		}
		
		//删除药品
		function deleteDrug() {

			var row = $("#dg_druginfo").datagrid("getSelected");
			var rows = $("#dg_druginfo").datagrid('getSelections');
			if (rows.length > 0) {
				var row = $("#dg_druginfo").datagrid("getSelected");
				if (row) {
					$('#dlg_deletedruginfo').dialog('open').dialog('setTitle',
							'删除药品');
					$("#ff_deletedruginfo").form("load", {

						"drugno" : row.drugno,

					});
					urls = "drug/deletedrug";
				}
			} else {
				$.messager.alert('提示', '请选择要删除的行', 'info');
			}

		}
		function deleteDrugDlg() {
			$("#ff_deletedruginfo").form("submit", {
				url : urls, //使用参数				
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.success == 'true') {
						$("#dg_druginfo").datagrid("reload");
						$("#dlg_deletedruginfo").dialog("close");
					}
					$.messager.show({
						title : "提示信息",
						msg : result.message
					});
				}
			});
		}
	</script>
</body>
</html>